package com.dubbo.server.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.dubbo.server.service.map.TodayBestServiceMapper;
import com.dubbo.server.utils.Cache;
import com.dubbo.server.vo.PageResult;
import com.dubbo.server.vo.RecommendUserQueryParam;
import com.dubbo.server.vo.TodayBest;
import com.tanhua.common.pojo.User;
import com.tanhua.common.utils.UserThreadLocal;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("tanhua")
@Slf4j
public class TodayBestController {

    @Reference
    TodayBestServiceMapper todayBestService;

    /**
     * 查询今日佳人
     * <p>
     * //   * @param user   当前登录对象
     *
     * @return
     */
    @GetMapping("todayBest")
    public ResponseEntity<TodayBest> queryTodayBest() {
        try {
            // todayBest 定义出来就是为了给前台做响应用的
            // VO对象  TodayBest(今日佳人对象)
            User user = UserThreadLocal.get();
            TodayBest todayBest = todayBestService.queryTodayBest(user);
            if (todayBest != null) {
                return ResponseEntity.ok(todayBest);
            }
        } catch (Exception e) {
            log.error("查询今日佳人出错~", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
     * 查询推荐用户列表
     * pojo  vo  dto: 数据传输对象
     * <p>
     * //* @param 拦截了token
     *
     * @param queryParam
     * @return
     */
    //@RequestMapping(method = RequestMethod.GET)
    @GetMapping("recommendation")
    @Cache(time = "1000")
    public ResponseEntity<PageResult> queryRecommendation(RecommendUserQueryParam queryParam) {
        try {
            User user = UserThreadLocal.get();
            PageResult pageResult = todayBestService.queryRecommendation(user, queryParam);
            if (null != pageResult) {
                return ResponseEntity.ok(pageResult);// 响应体中返回的  流
            }
        } catch (Exception e) {
            log.error("查询推荐用户列表出错~ token = ", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
